from django.shortcuts import render, redirect
from . import models

# Create your views here.
def index(requests):
    return render(requests, 'index.html')

def login(requests):
    if requests.method == 'GET':
        # 用户初次进入展示登录表单
        return render(requests, 'login.html')
    elif requests.method == 'POST':
        # 提交表单
        username = requests.POST.get('username')
        password = requests.POST.get('password')
        print(username, password)
        # 查询数据库    'select * from login_user where name=%s and password=%s' % (username, password)
        user = models.User.objects.filter(name=username, password=password).first()
        if not user:
            # 登录失败
            print('用户未注册，或密码错误')
            return redirect('/login/')
        # 登录成功
        print('注册成功')
        return redirect('/index/')



def register(requests):
    pass

def logout(requests):
    pass
